/*
 * Package il.ac.biu.cs.grossmm.api.data
 * File Replicatior.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 */

package il.ac.biu.cs.grossmm.api.flow;

import il.ac.biu.cs.grossmm.api.data.Node;
import il.ac.biu.cs.grossmm.api.data.Nodeset;

/**
 * Provides a way to link a data node (values and structure) to a different data
 * node or all data nodes in a given node set to a different node set
 */
public interface Replicatior {
	/**
	 * Called to start a replication transatcion
	 * 
	 * @param inspector
	 *            node inspector to read the source node
	 * @param manipulator
	 *            node manipulator to update the destination node
	 */
	void beginReplication(NodeInspector inspector, NodeManipulator manipulator);

	/**
	 * Links a source data node to a destination data node so that changes in
	 * the source node will be automatically reflected in the destination node
	 * 
	 * @param <N>
	 *            node type class
	 * @param src
	 *            the source node
	 * @param dest
	 *            the destination node
	 */
	<N> void link(Node<N> src, Node<N> dest);

	/**
	 * Unlinks all previously linked destination data nodes to a given source
	 * data node
	 * 
	 * @param <N>
	 *            node type class
	 * @param src
	 *            the source data hnode
	 */
	<N> void unlink(Node<N> src);

	/**
	 * Unlinks a previlusly linked source data node and destination data node
	 * 
	 * @param <N>
	 *            node type class
	 * @param src
	 *            the source data noe
	 * @param dest
	 *            the destination data node
	 */
	<N> void unlink(Node<N> src, Node<N> dest);

	/**
	 * Links a node set of a source data node to a node set of a destination
	 * data ndoe. Note that nodes may be of different node types, but the ndoe
	 * set type should be the same for the both nodes
	 * 
	 * @param <N>
	 *            source node type class
	 * @param <M>
	 *            destination node type class
	 * @param <S>
	 *            node type class
	 * @param src
	 *            source node
	 * @param srcSet
	 *            source node set
	 * @param dest
	 *            destination node
	 * @param dstSet
	 *            destination node set
	 */
	<N, M, S> void link(Node<N> src, Nodeset<N, S> srcSet, Node<M> dest,
		Nodeset<M, S> dstSet);

	/**
	 * Unlinks a node set of a source data node from any destination node sets
	 * 
	 * @param <N>
	 *            source node type class
	 * @param <S>
	 *            node type class
	 * @param src
	 * @param srcSet
	 */
	<N, S> void unlink(Node<N> src, Nodeset<N, S> srcSet);

	/**
	 * Unlinks a node set of a source data node from a specified node set of a
	 * destination node
	 * 
	 * @param <N>
	 *            source node type class
	 * @param <M>
	 *            destination node type class
	 * @param <S>
	 *            node type class
	 * @param src
	 *            source node
	 * @param srcSet
	 *            source node set
	 * @param dest
	 *            destination node
	 * @param dstSet
	 *            destination node set
	 */
	<N, M, S> void unlink(Node<N> src, Nodeset<N, S> srcSet, Node<M> dest,
		Nodeset<M, S> dstSet);

	/**
	 * Called to commit the replication transaction
	 * 
	 */
	void endReplication();
}
